﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;
using ASPNETVN.PORTAL.Components.Configuration;
using ASPNETVN.PORTAL.Components.Security;
using ASPNETVN.PORTAL.Components.Configuration.Items;

namespace ASPNETVN.PORTAL.Masters
{
    public partial class WEATHER : MasterPage
    {
        public bool ShowTabs = true;

        protected override void OnInit(EventArgs e)
        {
            // Obtain Portal from Current Context
            Portal portal = (Portal)HttpContext.Current.Items["Portal"];

            // Title of web site.
            this.Head.Title = portal.Title;

            // BEGIN: Load marquee
            PortalDataSet ds = PortalConfiguration.GetPortalDataSet();
            DataRow[] rows = ds.Marquee.Select(string.Format("PortalID = '{0}' AND Status = 1", Global.PortalID));
            foreach (DataRow row in rows)
            {
                LiteralControl marquee = new LiteralControl();
                marquee.Text = string.Format("<marquee scrolldelay='{0}' scrollamount='{1}'><div style='font-weight: bold; color: {3}'>{2}</div></marquee>", row["ScrollDelay"], row["ScrollAmount"], row["Text"], row["ForeColor"]);
                divMarquee.Controls.Add(marquee);
                break;
            }
            //END: Load marquee

            // If user logged in, customize welcome message
            if (Request.IsAuthenticated)
            {
                WelcomeMessage.Text = "<a href='" + Global.GetApplicationPath(Request) + "/Default.aspx?page=ChangePassword' class='SiteLink'>" + Global.RM.GetString("SYSTEM_WELCOME") + " " + PortalSecurity.CurrentUser.Identity.Email + "</a> <span>|</span>";
                WelcomeMessage.ToolTip = PortalSecurity.CurrentUser.Identity.ToString();


                //hlProfile.Visible = true;

                // if authentication mode is Cookie, provide a logoff link
                if (Context.User.Identity.AuthenticationType == "Forms")
                {
                    LogoffLink.Text = "<a href='" + Global.GetApplicationPath(Request) + "/Admin/Logoff.aspx' class=SiteLink> " + Global.RM.GetString("SYSTEM_LOGOUT") + "</a>";
                }

            }
            else
            {
                //hlProfile.Visible = false;
                // Allow register?
                if (portal.AllowRegister)
                {
                    LogoffLink.Text = "<a href='" + Global.GetApplicationPath(Request) + "/Register.aspx' class=SiteLink> " + Global.RM.GetString("SYSTEM_REGISTER") + "</a> <span>|</span> " + "<a href='" + Global.GetApplicationPath(Request) + "/SignIn.aspx' class=SiteLink> " + Global.RM.GetString("SYSTEM_SIGNIN") + "</a>";
                }
                else
                {
                    LogoffLink.Text = "<a href='" + Global.GetApplicationPath(Request) + "/SignIn.aspx' class=SiteLink> " + Global.RM.GetString("SYSTEM_SIGNIN") + "</a>";
                }
            }




            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            //if (PortalSecurity.IsInRole("1"))
            //{
            //    SlaveMenu.Visible = false;
            //}
        }
    }
}
